<template>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      :visible.sync="visible"
      :before-close="cancel"
      class="JNPF-dialog JNPF-dialog_center"
      lock-scroll
      width="60%"
    >
      <el-row :gutter="15" class="">
        <el-form  ref="elForm"  :model="dataForm"  :rules="rules" label-width="120px">
          <el-col :span="12">
            <el-form-item label="楼栋编号" class="required" prop="fpointNo">
              <el-input  v-model="dataForm.fpointNo"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称" class="required" prop="fsiteNo">
              <el-input  v-model="dataForm.fsiteNo"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="楼栋名称" class="required" prop="fpointName">
              <el-input  v-model="dataForm.fpointName"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="楼栋类型" class="required" prop="fpointFlag">
              <el-select v-model="dataForm.fpointFlag" placeholder="请选择">
                <el-option
                  v-for="item in selectlist2"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维度" class="required" prop="fpointL">
              <el-input  v-model="dataForm.fpointL"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="经度" class="required" prop="fpointD">
              <el-input  v-model="dataForm.fpointD"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="高度" class="required" prop="fpointH">
              <el-input  v-model="dataForm.fpointH"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="宽度" class="required" prop="fpointW">
              <el-input  v-model="dataForm.fpointW"  placeholder="请输入"  clearable>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" class="required" prop="fpointState">
              <el-select v-model="dataForm.fpointState" placeholder="请选择">
                <el-option
                  v-for="item in selectlist1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button  v-if="insertorupdate" type="primary" v-loading="loading" @click="HandelCreate">确 定</el-button>
        <el-button v-else type="primary"  v-loading="loading" @click="HandelupdateRoom">修 改</el-button>
      </span>
    </el-dialog>
  </template>
  <script>
  import {createRoom,updateRoom} from "@/api/data/room"
  export default {
    data() {
      return {
        title:"新增",
        dataForm:{
          id: undefined,
          fpointNo: undefined,
          fimage: undefined,
          fpointName: undefined,
          fsiteNo: '300017',
          fparentNo: 0,
          fpointFlag: "1",
          fpointL: undefined,
          fpointD: undefined,
          fpointH: undefined,
          fpointW: undefined,
          fpointState: "1",
          fupddate: new Date(),
          foperator: 20
        },
        selectlist1:[
        {
            "label": "禁用",
            "value": "0"
          },
          {
            "label": "启用",
            "value": "1"
          }
        ],
        selectlist2:[
          {
            "label": "室内",
            "value": "1"
          },
          {
            "label": "室外",
            "value": "2"
          }
        ],
        rules: {
          fpointNo: [
              { required: true, message: '请输入楼栋编号', trigger: 'blur' },
          ],
          fsiteNo: [
              { required: true, message: '请输入客户名称', trigger: 'blur' },
          ],
          fpointName: [
              { required: true, message: '请输楼栋名称', trigger: 'blur' },
          ],
          fpointFlag: [
              { required: true, message: '请输入楼栋类型', trigger: 'blur' },
          ],
          fpointState: [
              { required: true, message: '请选择状态', trigger: 'blur' },
          ]
        },
        loading:false,
        visible:false,
        insertorupdate:true
      };
    },
    created() {
    },
    mounted() {},
    methods: {
      //
      init(data){
          if(data!=undefined)
          {
              this.title="修改"
              this.dataForm=data;
             this.insertorupdate=false;
          }
          else
          {
            this.insertorupdate=true;
              this.title="新增";
          }
          this.visible=true;
      },
      //
      HandelCreate(){
        this.$refs["elForm"].validate((valid) => {
          if (valid) {
            createRoom(this.dataForm)
            .then(res=>{
              this.$message({
                message: '添加成功',
                type: 'success'
              });
              this.cancel();
            })
          }
        })
      },
      HandelupdateRoom(){
        this.$refs["elForm"].validate((valid) => {
          if (valid) {
            updateRoom(this.dataForm)
            .then(res=>{
              this.$message({
                message: '修改成功',
                type: 'success'
              });
              this.cancel();
            })
          }
        })
      },
      //
      cancel(){
          this.$refs.elForm.resetFields();
          this.visible=false;
      },
    },
  };
  </script>
  
  
  
  
  